/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.nii.qlks.BusinessLogicLayer;

import edu.nii.qlks.DataAccessLayer.MSSQLConnectUnit;
import edu.nii.qlks.DataTransferObject.CTPhieuDenInfo;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;

/**
 *
 * @author MARS_NHO
 */
public class CTPhieuDenBLL {
    MSSQLConnectUnit _connect;
    ResultSet  _result;
    
    public ArrayList LayDS(String Condition, String OderBy) throws Exception{
        ArrayList vt = new ArrayList();
        
        _connect = edu.nii.qlks.BusinessLogicLayer.BusinessLogicAbstract.getConnection();
        _result = _connect.Select("CTPHIEUDEN", Condition, OderBy);
        
        while (_result.next()){
            ArrayList vt_row = new ArrayList();
            vt_row.add(_result.getString(1));
            vt_row.add(_result.getString(2));
            vt_row.add(_result.getString(3));
            vt.add(vt_row);
        }
        _connect.Close();
        return vt;
    }
    
    public ArrayList LayDS(String Condition) throws Exception{
         return LayDS(Condition, null);
    }
    
    public ArrayList LayDS() throws Exception{
        return LayDS(null);
    }
    
    public void Insert(CTPhieuDenInfo cTPhieuDenInfo) throws Exception{
        _connect = edu.nii.qlks.BusinessLogicLayer.BusinessLogicAbstract.getConnection();
        HashMap<String, Object> map = new HashMap<>();
        map.put("MaCTPhieuDen", cTPhieuDenInfo.getMaCTPhieuDen());
        map.put("MaPhieuDen", cTPhieuDenInfo.getMaPhieuDen());
        map.put("MaKhachHang", cTPhieuDenInfo.getMaKhachHang());
        _connect.Insert("CTPHIEUDEN", map);
    }
    
    public void Inserts(HashSet<CTPhieuDenInfo> chiTietPhieuThueInfos) throws Exception{
        for (CTPhieuDenInfo chiTietPhieuThueInfo:chiTietPhieuThueInfos) {
            this.Insert(chiTietPhieuThueInfo);
        }
    }
    
    public void Update(CTPhieuDenInfo cTPhieuDenInfo) throws Exception{
        _connect = edu.nii.qlks.BusinessLogicLayer.BusinessLogicAbstract.getConnection();
        HashMap<String, Object> map = new HashMap<>();
        map.put("MaPhieuDen", cTPhieuDenInfo.getMaPhieuDen());
        map.put("MaKhachHang", cTPhieuDenInfo.getMaKhachHang());
        _connect.Update("CTPHIEUDEN", map, "MaCTPhieuDen = " + cTPhieuDenInfo.getMaCTPhieuDen());
    }
    
    public void Updates(HashSet<CTPhieuDenInfo> cTPhieuDenInfos) throws Exception{
        for (CTPhieuDenInfo cTPhieuDenInfo:cTPhieuDenInfos){
            this.Update(cTPhieuDenInfo);
        }
    }
    
    public void Delete(CTPhieuDenInfo cTPhieuDenInfo) throws Exception{
        _connect = edu.nii.qlks.BusinessLogicLayer.BusinessLogicAbstract.getConnection();
        _connect.Delete("CTPHIEUDEN", "MaCTPhieuDen = " + cTPhieuDenInfo.getMaCTPhieuDen());
    }
    
    public void Deletes(HashSet<CTPhieuDenInfo> cTPhieuDenInfos) throws Exception{
         for (CTPhieuDenInfo cTPhieuDenInfo:cTPhieuDenInfos){
            this.Delete(cTPhieuDenInfo);
        }
    }
    
    public String TaoMaTuDong(String maGoc, int batDau){
        return BusinessLogicAbstract.TaoMaTuDong(maGoc, batDau);
    }
}
